﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Actuals.CoreDomain;
using Actuals.CoreDomain.Data;

namespace Actuals.Data
{
    public class DalTaskStatus : Dal<ITaskStatus, TaskStatus>, IDalTaskStatus
    {
         private readonly IDalManager _manager;
        private static readonly IDalTaskStatus _instance = new DalTaskStatus();
        private const string SP_GET_TASKSTATUSES = "usp_GetTaskStatuses";
        private const string SP_GET_TASKSTATUS = "usp_GetTaskStatus";

        public static IDalTaskStatus Instance
        {
            get { return _instance; }
        }

        public DalTaskStatus()
        {
            _manager = new DalManager();
        }

        public DalTaskStatus(IDalManager manager)
        {
            _manager = manager;
        }

        protected override void Convert(ITaskStatus obj, DataRow row)
        {

            obj.StatusId = _manager.GetValue<int>(row, "StatusId");
            obj.StatusDescription = _manager.GetValue<string>(row, "StatusDescription");
            

        }

        public IList<ITaskStatus> GetTaskStatuses()
        {
            _manager.StoredProcedureName = SP_GET_TASKSTATUSES;
            
          

            List<ITaskStatus> taskStatuses = new List<ITaskStatus>();
            foreach (ITaskStatus taskStatus in ConvertAll(_manager.ExecuteDataSet()))
                taskStatuses.Add(taskStatus);

            return taskStatuses;
        }


        public ITaskStatus GetTaskStatus(int statusId)
        {
            _manager.StoredProcedureName = SP_GET_TASKSTATUS;
            _manager.AddInParameter("@StatusId", DbType.Int32, statusId);


            ITaskStatus taskStatus = new TaskStatus();
            Convert(taskStatus, _manager.ExecuteDataSet());
            return taskStatus;
        }
    }
}
